<template>
  <el-dialog :visible.sync="modelValue" title="快递柜信息" @close="resetForm">
    <el-form :model="lockerData" ref="form">
      <el-form-item label="快递柜ID" prop="id">
        <el-input v-model="lockerData.id" disabled></el-input>
      </el-form-item>
      <el-form-item label="位置" prop="location">
        <el-input v-model="lockerData.location"></el-input>
      </el-form-item>
      <el-form-item label="状态" prop="status">
        <el-select v-model="lockerData.status">
          <el-option label="可用" value="available"></el-option>
          <el-option label="不可用" value="unavailable"></el-option>
        </el-select>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="resetForm">取 消</el-button>
      <el-button type="primary" @click="submit">确 定</el-button>
    </span>
  </el-dialog>
</template>

<script setup>
import { ref, watch } from 'vue';

const props = defineProps({
  modelValue: Boolean,
  currentLocker: Object,
});

const emit = defineEmits(['submit']);

const lockerData = ref({ id: '', location: '', status: '' });

watch(() => props.currentLocker, (newLocker) => {
  if (newLocker) {
    lockerData.value = { ...newLocker };
  } else {
    resetForm();
  }
});

const resetForm = () => {
  lockerData.value = { id: '', location: '', status: '' };
};

const submit = () => {
  emit('submit', lockerData.value);
};
</script>

<style>

</style>